#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;

int n, m;
int a[N];
int f[N];

struct node
{
	int d, s, t;
}b[N];

void add(int l, int r, int x)
{
	f[l] += x, f[r + 1] -= x;
}

bool check(int x)
{
	for(int i = 1;i <= n;i ++) f[i] = a[i] - a[i - 1];
	for(int i = 1;i <= x;i ++) add(b[i].s, b[i].t, -b[i].d);
	for(int i = 1;i <= n;i ++)
	{
		f[i] = f[i - 1] + f[i];
		if(f[i] < 0) return false;
	}
	return true;
}

int main()
{
	cin >> n >> m;
	for(int i = 1;i <= n;i ++) cin >> a[i];
	for(int i = 1;i <= m;i ++) cin >> b[i].d >> b[i].s >> b[i].t;
	int l = 1, r = m;
	while(l < r)
	{
		int mid = l + r >> 1;
		if(check(mid)) l = mid + 1;
		else r = mid;
	}
	if(check(l)) cout << 0 << endl;
	else cout << -1 << endl << l << endl;
	return 0;
}